<template>
	<view class="header">
		<view class="header_left" @click="openSide">
			<rui-icons icon="menu" size="40"></rui-icons>
		</view>
		<view class="header_center">
			{{user.topname}}
		</view>
		<view class="header_right">
			<view class="header_right_msg" @click="clear">
				<rui-icons icon="delete" size="40"></rui-icons>
				<view class="header_right_tag" v-if="msg.len">
					{{msg.len}}
				</view>
			</view>

			<view class="header_right_share" @click="share">
				<rui-icons icon="share" size="40"></rui-icons>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		userStore,
		msgStore
	} from "@/store/index.js"
	const user = userStore();
	const msg = msgStore();
	const emits = defineEmits(['side']);

	const clear = () => {
		msg.clear()
	}
	let url = `${location.protocol}//${location.hostname}`
	const share = () => {
		uni.setClipboardData({
			data: `旅游助手，身份证归属地批量查询网址： ${url}`,
			success: () => {
				uni.showToast({
					title: '已复制网址',
					icon: 'success',
					duration: 2000,
				});
			}
		});
	}

	const openSide = () => {
		// refSide.value.open()
		emits('side')
	}
</script>

<style lang="scss" scoped>
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #f8f8f8;
		padding: 30rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		width: calc(100% - 60rpx);

		&_right {
			display: flex;

			&_tag {
				position: absolute;
				top: -15rpx;
				right: -20rpx;
				border-radius: 50%;
				background: #f00;
				color: #fff;
				font-size: 20rpx;
				text-align: center;
				line-height: 32rpx;
				width: 32rpx;
				height: 32rpx;
			}

			&_notify {
				margin-right: 40rpx;
				position: relative;
			}

			&_msg {
				margin-right: 40rpx;
				position: relative;
			}
		}
	}
</style>